package org.example.edusmart.utils;

import com.alibaba.dashscope.aigc.generation.Generation;
import com.alibaba.dashscope.aigc.generation.GenerationResult;
import com.alibaba.dashscope.aigc.generation.models.QwenParam;
import com.alibaba.dashscope.common.Message;
import com.alibaba.dashscope.common.MessageManager;
import com.alibaba.dashscope.common.Role;
import com.alibaba.dashscope.exception.ApiException;
import com.alibaba.dashscope.exception.InputRequiredException;
import com.alibaba.dashscope.exception.NoApiKeyException;
import com.alibaba.dashscope.utils.Constants;
import org.example.edusmart.request.Public.ChatPojo;

public class QianWenChat {
    public static GenerationResult callWithMessage(ChatPojo chatPojo) throws NoApiKeyException, ApiException, InputRequiredException
    {
        Constants.apiKey="sk-771d7e5415684d509b07daa8a2f33f1f";
        Generation gen = new Generation();

        MessageManager msgManager = new MessageManager(10);
        Message systemMsg =
                Message.builder().role(Role.SYSTEM.getValue()).content(chatPojo.getQuestion()).build();
        Message userMsg = Message.builder().role(Role.USER.getValue()).content(chatPojo.getQuestion()).build();
        msgManager.add(systemMsg);
        msgManager.add(userMsg);
        QwenParam param =
                QwenParam.builder().model(Generation.Models.QWEN_TURBO).messages(msgManager.get())
                        .resultFormat(QwenParam.ResultFormat.MESSAGE)
                        .topP(0.8)
                        .enableSearch(true)
                        .build();
        return gen.call(param);
    }
}
